// pages/home/healthDetails/index.js
import * as echarts from '../../../ec-canvas/echarts.min.js';
let chart = null;
const app = getApp()

function initChart(canvas, width, height, dpr) {
  const chart = echarts.init(canvas, null, {
    width: width,
    height: height,
    devicePixelRatio: dpr // new
  });
  canvas.setChart(chart);

  var option = {

    title: {
      subtext: '单位℃',
      top: 10,
      left: -5
    },
    color:['#FEB624','#17BB89'],
    legend: {
      data: ['国标', '当前数值'],
      left:'right'
    },
    grid: {
      x: 22,
      y: 45,
      x2: 5,
      y2: 20,
      borderWidth: 1
    },
    xAxis: {
      type: 'category',
      data: ['7:00', '8:00', '9:00', '10:00', '11:00', '12:00']
    },
    yAxis: {
      type: 'value'
    },
    series: [{
        name: '国标',
        symbol: "none",
        type: 'line',
        data: [15, 15, 15, 15,15, 15],
        itemStyle: {
          normal: {
            lineStyle: {
              color: "#FEB624" //折线的颜色
            }
          }
        },
        smooth: true
      },
      {
        name: '当前数值',
        symbol: "none",
        type: 'line',
        data: [0, 10, 5, 16,20,12],
        itemStyle: {
          normal: {
            lineStyle: {
              color: "#17BB89" //折线的颜色
            }
          }
        },
        smooth: true
      }
    ]
  };

  chart.setOption(option);
  return chart;
}
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [{
        index: 0,
        name: "温度"
      },
      {
        index: 1,
        name: "虫情监测"
      },
      {
        index: 2,
        name: "植株病害"
      },
      {
        index: 3,
        name: "湿度"
      }
    ],
    healthList: [
      {
        id:0,
        time:"2021-01-28",
        temp:"20℃",
        level:"偏高",
        scheme:"解决方案"
      },
      {
        id:1,
        time:"2021-01-28",
        temp:"20℃",
        level:"偏高",
        scheme:"解决方案"
      },
      {
        id:2,
        time:"2021-01-28",
        temp:"20℃",
        level:"偏高",
        scheme:"解决方案"
      },
      {
        id:3,
        time:"2021-01-28",
        temp:"20℃",
        level:"偏高",
        scheme:"解决方案"
      },
      {
        id:4,
        time:"2021-01-28",
        temp:"20℃",
        level:"偏高",
        scheme:"解决方案"
      },
      {
        id:5,
        time:"2021-01-28",
        temp:"20℃",
        level:"偏高",
        scheme:"解决方案"
      },
      {
        id:6,
        time:"2021-01-28",
        temp:"20℃",
        level:"偏高",
        scheme:"解决方案"
      },
    ],
    situationList: [
      {
        url: "../../../images/banner.png",
        text: "黄瓜根结线虫"
      },
      {
        url: "../../../images/banner.png",
        text: "黄瓜根结线虫"
      }
    ],
    selectIndex: 0,
    ec: {
      onInit: initChart
    }
  },

  changeItem: function (e) {
    console.log(e.currentTarget.dataset)
    this.setData({
      selectIndex: e.currentTarget.dataset.type
    })
  },

  goPages: function(e) {
    let type = e.currentTarget.dataset['type'],
        title = '专业方案';
    wx.navigateTo({
      url: `/pages/home/${type}/index`,
      success: function(res) {
        wx.setNavigationBarTitle({title})
        // 通过eventChannel向被打开页面传送数据
        // res.eventChannel.emit('acceptDataFromOpenerPage', { data: 'test' })
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})